<!--
<template>
  <a-card :bordered="false">

    &lt;!&ndash; 查询区域 &ndash;&gt;
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">

          <a-col :md="6" :sm="8">
            <a-form-item label="分类名称">
              <a-input placeholder="请输入分类名称" v-model="queryParam.name"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="sReset" icon="reload" style="margin-left: 8px">重置</a-button>
              &lt;!&ndash;<a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>&ndash;&gt;
            </span>
          </a-col>

        </a-row>
      </a-form>
    </div>

    &lt;!&ndash; 操作按钮区域 &ndash;&gt;
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
    </div>

    &lt;!&ndash; table区域-begin &ndash;&gt;
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
      <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{
      selectedRowKeys.length }}</a>项
      <a style="margin-left: 24px" @click="onClearSelected">清空</a>
    </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipaginations"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange">

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical"/>
          <a @click="openDetail(record)">子分类</a>

          <a-divider type="vertical"/>
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down"/></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>
    &lt;!&ndash; table区域-end &ndash;&gt;

    &lt;!&ndash; 表单区域 &ndash;&gt;
    <type-modal ref="modalForm" @ok="modalFormOk"></type-modal>
    <type-detail ref="detailForm"></type-detail>
  </a-card>
</template>

<script>
  import TypeModal from './modules/TypeModal'
  import TypeDetail from './modules/TypeDetail'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import { getAction } from '../../api/manage'

  export default {
    name: 'TypeList',
    mixins: [JeecgListMixin],
    components: {
      TypeModal,
      TypeDetail
    },
    data() {
      return {
        description: '分类表管理页面',
        // 表头
        columns: [
          {
            title: '编号',
            dataIndex: '',
            key: 'rowIndex',
            width: 60,
            align: 'center',
            customRender: function(t, r, index) {
              return parseInt(index) + 1
            }
          },
          {
            title: '分类名称',
            align: 'center',
            dataIndex: 'name'
          },
          {
            title: '创建者',
            align: 'center',
            dataIndex: 'createBy'
          },
          {
            title: '创建时间',
            align: 'center',
            dataIndex: 'createTime'
          },
          {
            title: '最后更新者',
            align: 'center',
            dataIndex: 'updateBy'
          },
          {
            title: '最后更新时间',
            align: 'center',
            dataIndex: 'updateTime'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align: 'center',
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: '/type/list',
        },
        ipaginations: {
          current: 1,
          pageSize: 10,
          pageSizeOptions: ['10', '20', '30'],
          showTotal: (total, range) => {
            return range[0] + '-' + range[1] + ' 共' + total + '条'
          },
          showQuickJumper: true,
          showSizeChanger: true,
          total: 0
        },
        queryParam:{
          name:''
        }
      }
    },
    computed: {
      importExcelUrl: function() {
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
      }
    },
    methods: {
      loadDate(){
        let params = {
          pageNo: this.ipaginations.current,
          pageSize: this.ipaginations.pageSize,
          name: this.queryParam.name
        }
        getAction(this.url.list, params).then((res) => {
          this.dataSource = res.result
          this.ipaginations.total = res.result.length
        }).finally(() => {
          this.loading = false
        })
      },
      /**
       * 重置查询
       */
      sReset() {
        this.queryParam.name = ''
        this.searchQuery()
      },
      modalFormOk(){
        this.ipaginations=this.$options.data().ipaginations
        this.sReset()
      },
      searchQuery(){
        let params = {
          pageNo: this.ipaginations.current,
          pageSize: this.ipaginations.pageSize,
          name: this.queryParam.name
        }
        getAction(this.url.list, params).then((res) => {
          this.dataSource = res.result
          this.ipaginations.total = res.result.length
        }).finally(() => {
          this.loading = false
        })
      },
      openDetail: function(record) {
        this.$refs.detailForm.openView(record)
      }
    },
    mounted() {
      this.loadDate()
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less'
</style>-->
<template>
  <a-card :bordered="false">

    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="24">

          <a-col :md="6" :sm="8">
            <a-form-item label="分类名称">
              <a-input placeholder="请输入分类名称" v-model="queryParam.name"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <a-form-item label="所属单位">
              <a-select
                placeholder="请选择所属单位"
                optionFilterProp="children"
                v-model="queryParam.workCode">
                <a-select-option v-for="wcs in workCodes"  :value="wcs.value">{{wcs.text}}
                </a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8" >
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置查询</a-button>
            </span>
          </a-col>

        </a-row>
      </a-form>
    </div>

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
    </div>

    <!-- table区域-begin -->
    <div>
      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange">

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />
          <a @click="openDetail(record)">子分类</a>
          <a-divider type="vertical"/>
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record)">
                  <a><a-icon type="delete"/>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>
    <!-- table区域-end -->

    <!-- 表单区域 -->
    <type-modal ref="modalForm" @ok="succeedOK"></type-modal>
    <type-detail ref="detailForm"></type-detail>
  </a-card>
</template>

<script>
  import TypeModal from './modules/TypeModal'
  import TypeDetail from './modules/TypeDetail'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import { deleteAction, getAction } from '../../api/manage'
  import { mapGetters } from 'vuex'
  import { initDictOptions } from '../../components/dict/JDictSelectUtil'

  export default {
    name: 'TypeList',
    mixins: [JeecgListMixin],
    components: {
      TypeModal,
      TypeDetail
    },
    data () {
      return {
        description: '文物分类',
        dataSource: [],
        ipagination: {
          current: 1,
          pageSize: 10,
          pageSizeOptions: ['10', '20', '30'],
          showTotal: (total, range) => {
            return range[0] + '-' + range[1] + ' 共' + total + '条'
          },
          showQuickJumper: true,
          showSizeChanger: true,
          total: 0
        },
        queryParam:{
          name:'',
          workCode:undefined
        },
        workCodes:[],
        url: {
          list: "/type/list",
          delete: "/type/delete"
        },
      }
    },
    computed: {
      importExcelUrl: function() {
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
      columns() {
        let that = this
        const columns = [
          {
            title: '序号',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt((that.ipagination.current-1)*that.ipagination.pageSize) +index+ 1
            }
          },
          {
            title: '分类名称',
            align: 'center',
            dataIndex: 'name'
          },
          {
            title: '所属单位',
            align: 'center',
            dataIndex: 'workCode'
          },
          {
            title: '创建者',
            align: 'center',
            dataIndex: 'createBy'
          },
          {
            title: '创建时间',
            align: 'center',
            dataIndex: 'createTime'
          },
          {
            title: '最后更新者',
            align: 'center',
            dataIndex: 'updateBy'
          },
          {
            title: '最后更新时间',
            align: 'center',
            dataIndex: 'updateTime'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align: 'center',
            scopedSlots: { customRender: 'action' }
          }
        ]
        return columns

      },

    },
    created() {
      this.initDictConfig()
    },
    methods: {
      ...mapGetters(['userInfo']),
      //数据字典获取单位代码
      initDictConfig() {
        initDictOptions('work_code').then((res) => {
          if (res.success) {
            this.workCodes = res.result
          }
        })
      },
      loadData() {
        let params = {
          pageNo: this.ipagination.current,
          pageSize: this.ipagination.pageSize,
          name: this.queryParam.name,
          workCode: this.queryParam.workCode

        }
        getAction(this.url.list, params).then((res) => {
          this.dataSource = res.result.list
          this.ipagination.total = res.result.total
          this.loading=false
        }).catch((e) => {
          this.$message.error('发生异常!')
        })
      },
      succeedOK(){
        this.ipagination=this.$options.data().ipagination
        this.queryParam=this.$options.data().queryParam
        this.loadData()
      },
      openDetail: function(record) {
        this.$refs.detailForm.openView(record)
      },
      handleDelete(record){
        let params = {
          id:record.id
        }
        deleteAction(this.url.delete,params).then((res)=>{
          if (res.success){
            this.$message.success(res.message)
            this.loadData()
          }else {
            this.$message.error("删除失败")
          }
        })
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less'
</style>